<?php
require( dirname(__FILE__) . '/../../../wp-load.php' ); 
nocache_headers();

if (!isset($_SESSION)) {
 	session_start();
	//session_regenerate_id();
}

$user = $_SESSION['userdata'];



$postid = $_POST["postid"];
$score = $_POST["score"];

$gameTotalScore = get_post_meta($postid, "GameTotalScore", true);
$gameTotalScoreTimes = get_post_meta($postid, "GameTotalScoreTimes", true);
if($gameTotalScore){
	update_post_meta($postid, "GameTotalScore", $gameTotalScore + $score);	
	update_post_meta($postid, "GameTotalScoreTimes", $gameTotalScoreTimes + 1);
}else{
	add_post_meta($postid, "GameTotalScore",  $score);	
	add_post_meta($postid, "GameTotalScoreTimes", 1);
}

if($user){
	addUserEmpiricalValue($user->ID, 30);
}

echo (($gameTotalScore + $score)/($gameTotalScoreTimes + 1)).":".($gameTotalScoreTimes + 1);


?>